package com.financing.platform.dao.impl;

import java.sql.SQLException;
import java.util.Collections;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.financing.platform.dao.ISwitchDao;
import com.financing.platform.dto.SwitchDTO;
import com.financing.platform.util.SqlName;


@Repository("switchDaoImpl")
public class SwitchDaoImpl extends BaseDaoImpl implements ISwitchDao {

	@SuppressWarnings("unchecked")
	public List<SwitchDTO> queryAllSwitch() {
		try {
			return (List<SwitchDTO>) this.sqlMapClient.queryForList(SqlName.querySwitch,null);
		} catch (SQLException e) {
			log.error("Query switch error !");
			return Collections.emptyList();
		}
	}

	public int updateSwitch(SwitchDTO switchDTO) {
		try {
			this.sqlMapClient.update(SqlName.updateSwitch, switchDTO);
			return 1;
		} catch (SQLException e) {
			log.error("Update switch error!" ,e);
			return 0;
		}
	}

	public int addSwitch(SwitchDTO switchDTO) {
		try {
			this.sqlMapClient.insert(SqlName.addSwitch, switchDTO);
			return 1;
		} catch (SQLException e) {
			log.error("Add switch error !", e);
			return 0;
		}
	}

	public SwitchDTO querySwitch(SwitchDTO switchDTO) {
		try {
			return (SwitchDTO) this.sqlMapClient.queryForObject(SqlName.querySwitch,switchDTO);
		} catch (SQLException e) {
			log.error("query switch error!",e);
			return switchDTO;
		}
	}

}
